<?php
/**
 * Automaticke nacitanie tried. Pozri http://us3.php.net/manual/en/language.oop5.autoload.php
 * @param $class Nazov triedy
 * @package bakalarka
 */
function __autoload($class)
{
	if(substr($class, -strlen('Model')) == 'Model' &&
		strlen($class) > 5)
		$file = APPROOT.'model'.DS.$class.'.php';
	else if(substr($class, -strlen('Controller')) == 'Controller' &&
		strlen($class) > 10)
		$file = APPROOT.'controller'.DS.$class.'.php';
	else if(substr($class, -strlen('Language')) == 'Language' &&
		strlen($class) > 8)
		$file = APPROOT.'language'.DS.$class.'.php';
	else if(substr($class, -strlen('Writer')) == 'Writer' &&
		strlen($class) > 6)
		$file = APPROOT.'template'.DS.'writer'.DS.$class.'.php';
	else if(substr($class, -strlen('Form')) == 'Form' &&
		strlen($class) > 4)
		$file = APPROOT.'form'.DS.$class.'.php';
	else
		$file = APPROOT.'lib'.DS.$class.'.php';

	if(!file_exists($file))
		throw new Exception('L::errorObjectNotFound;'.
			json_encode(array($class)));
	
	include_once($file);
	if (!class_exists($class, false) && !interface_exists($class, false)) {
		throw new Exception('L::errorObjectNotFound;'.
			json_encode(array($class)));
	}
}
